define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sales/checkoutgoods/index' + location.search,
                    // add_url: 'sales/checkoutgoods/add',
                    // edit_url: 'sales/checkoutgoods/edit',
                    // del_url: 'sales/checkoutgoods/del',
                    multi_url: 'sales/checkoutgoods/multi',
                    table: 'sales_checkout_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                rowStyle:function(row, index){
                    if (row.status == 0) {
                        return{
                            css:{
                                color:'red'
                            }
                        }
                    }else{
                        return{}
                    }
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods.title', title: __('goods.title'), operate:'LIKE'},
                        {field: 'goods.specs', title: __('goods.specs')},
                        // {field: 'goods.place_origin', title: __('goods.place_origin'), operate:false},
                        {field: 'customer.company', title: __('customer.company'), operate:'LIKE'},
                        {field: 'customer.nickname', title: __('customer.nickname')},
                        {field: 'salescheckout.number', title: __('Salescheckout.number')},
                        {field: 'salesslip.number', title: __('Salesslip.number')},
                        {field: 'storehouse.name', title: __('Storehouse.name'),searchList: $.getJSON(Config.this_url+"/config/zaxconfig?states=1")},
                        {field: 'goods_num', title: __('Goods_num'),operate:false},
                        {field: 'sale_price', title: __('Sale_price'), operate:false},
                        {field: 'tax', title: __('Tax'), operate:false},
                        {field: 'ht_price', title: __('Ht_price'), operate:false},
                        {field: 'sf_price', title: __('sf_price'), operate:false},
                        {field: 'remark', title: __('Remark'), operate:false},
                        // {field: 'status', title: __('Status')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});